// Copyright Wilfried Woivre - http://blog.woivre.fr

using System;
using System.Data.Services.Providers;
using System.Linq;
using Demo.TableStorageDataServices.Web.Models;

namespace Demo.TableStorageDataServices.Web.Services
{
	public abstract class BaseDataSource : IDataSource
	{
		public abstract IQueryable< Response> Responses { get; } 
		public abstract IQueryable< Enigma> Enigmas { get; } 
		public abstract IQueryable< User> Users { get; } 

		public IQueryable GetQueryable(ResourceSet set)
		{
			if (set.Name == "Responses")
				return Responses.AsQueryable();
			if (set.Name == "Enigmas")
				return Enigmas.AsQueryable();
			if (set.Name == "Users")
				return Users.AsQueryable();
			throw new NotSupportedException(string.Format("{0} not found", set.Name));
		}

		public abstract object CreateResource(ResourceType resourceType);

        public abstract void AddResource(ResourceType resourceType, object resource);

        public abstract void DeleteResource(object resource);

        public abstract void SaveChanges(); 
	}
}

